package com.jz.community.modulemine.rechargephone.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.RxDataTool;
import com.jz.community.modulemine.R;
import com.jz.community.modulemine.rechargephone.bean.FareSection;

import java.util.List;


/**
 * Created by Ani_H on 2018/1/11.
 */

public class FareDealAdapter extends BaseSectionQuickAdapter<FareSection, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param layoutResId      The layout resource id of each item.
     * @param sectionHeadResId The section head layout id for each item
     * @param data             A new list is created out of this one to avoid mutable list
     */
    public FareDealAdapter(int layoutResId, int sectionHeadResId, List<FareSection> data) {
        super(layoutResId, sectionHeadResId, data);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, FareSection entity) {
        helper.setText(R.id.money_list_title, entity.header);

    }

    @Override
    protected void convert(BaseViewHolder helper, FareSection entity) {
        String payType = entity.t.getPayType();
        String sPayType = "";

        if (payType.equals("Ecard")) {
            //社区人E卡支付
            sPayType = "社区人E卡";
        } else if (payType.equals("Alipay")) {
            sPayType = "支付宝";
        } else if (payType.equals("MicroMessenger")) {
            sPayType = "微信";
        }

        //手机号码
        helper.setText(R.id.item_fare_phone, entity.t.getPhoneNum());
        //付款时间
        helper.setText(R.id.item_fare_time, entity.t.getCreateTime());
        //支付方式
        helper.setText(R.id.item_fare_pay, sPayType);
        //话费金额
        helper.setText(R.id.item_fare_phone_fare, "(¥" + entity.t.getPaymentAmount() + ")");
        //付款金额
        helper.setText(R.id.item_fare_pay_fare, "¥" + entity.t.getRechargeAmount());
        //支付状态
        TextView tvStatus = helper.getView(R.id.item_fare_status);
        ImageView tips = helper.getView(R.id.item_fare_tips);

        //0:待支付 1:等待支付结果确认 2:支付成功 3:支付失败 4:充值成功 5:充值失败 6:充值进行中 7:订单退款成功 8:订单退款失败
        if (!RxDataTool.isNullString(entity.t.getRechargeStatus())) {
            if (RxDataTool.isInteger(entity.t.getRechargeStatus())) {
                int status = Integer.parseInt(entity.t.getRechargeStatus());
                switch (status) {
                    case 1:
                        tvStatus.setText("待支付");
                        tvStatus.setTextColor(0xfff2383b);
                        tips.setVisibility(View.GONE);
                        break;
                    case 2:
                        tvStatus.setText("支付成功");
                        tvStatus.setTextColor(0xff666666);
                        tips.setVisibility(View.GONE);
                        break;
                    case 3:
                        tvStatus.setText("支付失败");
                        tvStatus.setTextColor(0xff666666);
                        tips.setVisibility(View.GONE);
                        break;
                    case 4:
                        tvStatus.setText("充值成功");
                        tvStatus.setTextColor(0xff41af35);
                        tips.setVisibility(View.GONE);
                        break;
                    case 5:
                        tvStatus.setText("充值失败");
                        tvStatus.setTextColor(0xff666666);
                        tips.setVisibility(View.VISIBLE);
                        break;
                    case 6:
                        tvStatus.setText("充值中");
                        tvStatus.setTextColor(0xfff2383b);
                        tips.setVisibility(View.GONE);
                        break;
                    case 7:
                        tvStatus.setText("退款成功");
                        tvStatus.setTextColor(0xff666666);
                        tips.setVisibility(View.GONE);
                        break;
                    case 8:
                        tvStatus.setText("退款失败");
                        tvStatus.setTextColor(0xff666666);
                        tips.setVisibility(View.GONE);
                        break;
                    default:
                        break;
                }
            }

        }


    }
}
